<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目合同列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目名称：</label>
                                <input type="text" autoComplete="off" name="xmmc"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                 <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="gcgl:xmxq:edit"> -->
<!--                     <i class="fa fa-edit"></i> 修改 -->
<!--                 </a> -->
                <a class="btn btn-primary single disabled" onclick="saveZsht()" shiro:hasPermission="gcgl:xmxq:ht">
                    <i class="fa fa-edit"></i> 上传正式合同
                </a>
<!--                 <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="gcgl:xmxq:remove"> -->
<!--                     <i class="fa fa-remove"></i> 删除 -->
<!--                 </a> -->
<!--                 <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="gcgl:xmxq:export"> -->
<!--                     <i class="fa fa-download"></i> 导出 -->
<!--                 </a> -->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:src="@{/ruoyi/base64.min.js?v=20231208}"></script>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('gcgl:xmxq:edit')}]];
        var removeFlag = [[${@permission.hasPermi('gcgl:xmxq:remove')}]];
        var editZjlFlag = [[${@permission.hasPermi('gcgl:project:editZjl')}]];
        var prefix = ctx + "gcgl/xmxq";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                detailUrl: prefix + "/detail/{id}",
                modalName: "合同详情",
                sortName: "a.orderno desc",
                sortOrder: "",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'gcProjectid',
                    title: '合同ID',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '项目编号'
                },
                {
                    field: 'xmmc',
                    title: '项目名称'
                },
                {
                    field: 'customerName',
                    title: '单位名称'
                },
                {
                    field: 'xmdz',
                    title: '项目地址',
                    visible: false
                },
                {
                    field: 'htje',
                    title: '合同总金额'
                },
                {
                    field: 'kpsl',
                    title: '开票税率',
                    visible: false
                },
                {
                    field: 'fkfs',
                    title: '支付方式',
                    visible: false
                },
                {
                    field: 'riq',
                    title: '签订日期',
                    width: '90'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status==0 || row.status==2 || row.status==4){
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editHome(\'' + row.gcProjectid + '\')"><i class="fa fa-plus"></i>上传项目资料</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                    	return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function saveZsht(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            var status = $.table.selectColumns("status").join();
            if (status == 3) {
            	$.modal.openTab('上传正式合同',"/gcgl/xmxq/editZsht/"+rows.join());
            }else if (status == 5) {
            	$.modal.alertWarning("项目已结项！");
                return;
            }else{
            	$.modal.alertWarning("项目没有审核通过！");
                return;
            }
        }
        
        function editHome(projectId) {
            $.modal.openTab('打开',"/gcgl/project/editHome/"+projectId);
        }
    </script>
</body>
</html>